package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.mapper.BrandMapper;
import cn.tedu.csmall.product.pojo.dto.BrandAddNewDTO;
import cn.tedu.csmall.product.pojo.entity.Brand;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BrandController {
    @Autowired
    BrandMapper brandMapper;

    @RequestMapping("/add-new")
    public String addNew(BrandAddNewDTO brandAddNewDTO){
        System.out.println("brandAddNewDTO = " + brandAddNewDTO);
        int count = brandMapper.countByName(brandAddNewDTO.getName());
        if (count>0) {
            return "shibai";
        }
        Brand brand = new Brand();
        BeanUtils.copyProperties(brandAddNewDTO,brand);
        brand.setSales(0);
        brand.setProductCount(0);
        brand.setCommentCount(0);
        brand.setPositiveCommentCount(0);
        brandMapper.insert(brand);
        return "aaaa";
    }

    @RequestMapping("/delete")
    public String delete(){
        System.out.println("Brand");
        return "aaaa";
    }
}
